package com.stx.jeepay.core.mq.vender.rocketmq;

import com.stx.jeepay.core.enums.MQVenderCS;
import com.stx.jeepay.core.mq.executor.MqThreadExecutor;
import com.stx.jeepay.core.mq.model.PayOrderReissueMQ;
import com.stx.jeepay.core.mq.vender.IMQMsgReceiver;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

/**
 * 业务：  支付订单补单（一般用于没有回调的接口，比如微信的条码支付）
 */
@Component
@ConditionalOnBean(PayOrderReissueMQ.IMQReceiver.class)
@RocketMQMessageListener(topic = PayOrderReissueMQ.MQ_NAME, consumerGroup = PayOrderReissueMQ.MQ_NAME)
public class PayOrderReissueRocketMQReceiver implements IMQMsgReceiver, RocketMQListener<String> {

    @Autowired
    private PayOrderReissueMQ.IMQReceiver mqReceiver;

    @Override
    public void receiveMsg(String msg) {
        mqReceiver.receive(PayOrderReissueMQ.parse(msg));
    }

    @Override
    @Async(MqThreadExecutor.EXECUTOR_PAYORDER_MCH_NOTIFY)
    public void onMessage(String message) {
        this.receiveMsg(message);
    }
}
